﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;

namespace Sunspot
{
    public abstract class Component
    {
        public int Handle { get; set; }
        public List<Component> Children { get; set; }
        public Component Parent { get; set; }
        public ComponentStyle Style { get; set; }

        public Component()
        {
            Children = new List<Component>();
        }

        public void Resize(int newWidth, int newHeight)
        {
            Style.Bounds = new Rectangle(Style.Bounds.X, Style.Bounds.Y, newWidth, newHeight);
        }
        public void Hide()
        {
            Style.Visible = false;
        }
        public void Show()
        {
            Style.Visible = true;
        }
        public void Offset(Vector2 offsetAmount)
        {
            Style.Position += offsetAmount;
            Style.Bounds = new Rectangle(Style.Bounds.X + (int)offsetAmount.X, Style.Bounds.Y + (int)offsetAmount.Y,
                Style.Bounds.Width, Style.Bounds.Height);
            foreach (var child in Children)
                child.Offset(offsetAmount);
        }
        public abstract void Update(GameTime gameTime, KeyboardState keyboardState, MouseState mouseState);
        public abstract void Draw(GameTime gameTime, SpriteBatch spriteBatch, ComponentStyle componentStyle);
    }
}
